<?php
class AdminModel{
	 private $tableName = 'e_administrate';
	/**
	 * 通过AdminName获取管理员用户的详细信息
	 * @param unknown_type $adminName
	 * @return E_AdminLib
	 */
	public function getByAdminName($adminName){
		$sql = "select * from $this->tableName where AdminName ='$adminName' limit 0,1";
		$result = mysql_query ( $sql ) or die ( mysql_error () );
		return mysql_fetch_assoc($result);
	}
	public function getById($id){
		$sql = "select * from $this->tableName where Id='$id' limit 0,1";
		$result = mysql_query ( $sql ) or die ( mysql_error () );
		return mysql_fetch_object($result);
	}
	
    public function addInfo ($info)
    {
        $model = new E_administrate();
        $sql = "insert into $this->tableName (";
        foreach ($model as $key => $value) {
            if (isset($info->$key)) {
                $sql .= "$key,";
            }
        }
        $sql = substr($sql, 0, - 1);
        $sql .= ") values (";
        foreach ($model as $key => $value) {
            if (isset($info->$key)) {
                $sql .= "'" . addslashes($info->$key) . "',";
            }
        }
        $sql = substr($sql, 0, - 1);
        $sql .= ");";
       return  mysql_query($sql);
    }
    public function setInfoByAdminName ($info, $adminName)
    {
        $model = new E_administrate();
        $sql = "update $this->tableName set ";
        foreach ($model as $key => $value) {
            if (isset($info->$key)) {
                $sql .= "`" . $key . "`='" . addslashes($info->$key) . "',";
            }
        }
        $sql = substr($sql, 0, - 1);
        $sql .= " where `AdminName` = '$adminName' limit 1";
        return mysql_query($sql);
    }
    
    public function getList ()
    {
        $sql = "select * from $this->tableName order by Id asc";
        $result = mysql_query($sql);
        $info = array();
        while ($row = mysql_fetch_assoc($result)) {
            $info[] = $row;
        }
        return $info;
    }
    public function delById ($id)
    {
        $sql = "delete from $this->tableName where Id=$id limit 1";
        return mysql_query($sql);
    }
}